package com.thinkgem.jeesite.modules.sys.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.BasePage;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.thinkgem.jeesite.modules.sys.entity.SysUserChangeLog;
import com.thinkgem.jeesite.modules.sys.service.SysUserChangeLogService;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户信息变更记录Controller
 *
 * @author kongxiangsheng
 * @version 2018-09-30
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/sysUserChangeLog")
@Slf4j
public class SysUserChangeLogController extends BaseController {
    @Autowired
    private SysUserChangeLogService sysUserChangeLogService;

    @RequiresPermissions("sys:sysUserChangeLog:view")
    @RequestMapping(value = {"list", ""})
    public String list(SysUserChangeLog sysUserChangeLog, HttpServletRequest request, HttpServletResponse response, Model model) {
        BasePage<SysUserChangeLog> page = new BasePage<SysUserChangeLog>(request, response);
        sysUserChangeLogService.page(page, new QueryWrapper<SysUserChangeLog>(sysUserChangeLog));

        model.addAttribute("page", page);
        return "modules/sys/SysUserChangeLog/list";
    }

    @RequiresPermissions("sys:sysUserChangeLog:view")
    @RequestMapping(value = "form")
    public String form(SysUserChangeLog sysUserChangeLog, Model model) {
        if (StringUtils.isNotBlank(sysUserChangeLog.getId())) {
            sysUserChangeLog = sysUserChangeLogService.getById(sysUserChangeLog.getId());
        }
        model.addAttribute("sysUserChangeLog", sysUserChangeLog);
        return "modules/sys/SysUserChangeLog/form";
    }

    @RequiresPermissions("sys:sysUserChangeLog:edit")
    @RequestMapping(value = "save")
    public String save(SysUserChangeLog sysUserChangeLog, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, sysUserChangeLog)) {
            return form(sysUserChangeLog, model);
        }
        sysUserChangeLogService.saveOrUpdate(sysUserChangeLog);
        addMessage(redirectAttributes, "保存用户信息变更记录成功");
        return "redirect:" + adminPath + "/sys/sysUserChangeLog/?repage";
    }

    @RequiresPermissions("sys:sysUserChangeLog:edit")
    @RequestMapping(value = "delete")
    public String delete(SysUserChangeLog sysUserChangeLog, RedirectAttributes redirectAttributes) {
        sysUserChangeLogService.removeById(sysUserChangeLog.getId());
        addMessage(redirectAttributes, "删除用户信息变更记录成功");
        return "redirect:" + adminPath + "/sys/sysUserChangeLog/?repage";
    }

}